@extends('app')

@section('content')
<ul class="nav nav-tabs">
    <li><a href="/admin/teaches/index">列表</a></li>
     <li class="active"><a href="#">编辑</a></li>
</ul>
    <form id="newsForm">
        <div class="content-edit-left" id="content-edit-left">
            <div class="captions">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属企业：</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="company_id" class="form-control">
                            <option value="0" @if($result->company_id == 0) selected @endif>青苜网站</option>
                            @foreach($companys as $company)
                            <option value="{{ $company->id }}" @if($result->company_id == $company->id) selected @endif>{{ $company->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章标题：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" class="form-control" name="title" id="title" placeholder="标题" value="{{ $result->title }}">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="from-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择分类：</label>
                    <div class="col-sm-3 col-xs-12" id="parent">
                        <select name="type" class="form-control" id="type" onchange="getChilds('category',this.value,'parent')">
                            <option value="0">请选择分类</option>
                            @foreach($type as $tp)
                            <option value="{{ $tp->cat_id }}" @if(in_array($tp->cat_id,$categorys['id'])) selected @endif>{{ $tp->cat_name }}</option>
                            @endforeach
                        </select>
                    </div>
                    @if($item != 5)
                    @foreach($categorys['list'] as $k=>$cglist)
                        <div class="col-sm-3 col-xs-12" id="child_{{$k-$item}}">
                            <select name="child_{{ $k-$item }}" class="form-control" id="child" onchange="getChilds(this.value,'child_{{ $k-$item }}')">
                        		<option value="0">请选择分类</option>
                        		@foreach($cglist as $cgl)
                        		<option value="{{ $cgl->cat_id }}" @if(in_array($cgl->cat_id,$categorys['id'])) selected @endif>{{ $cgl->cat_name }}</option>
                        		@endforeach
                        	</select>
                        </div>
                    @endforeach
                    @endif
                    @if($item ==5)
                    <div class="col-sm-3 col-xs-12" id="child_1"></div>
                    <div class="col-sm-3 col-xs-12" id="child_2"></div>
                    <div class="col-sm-3 col-xs-12" id="child_3"></div>
                    @elseif($item==4)
                    <div class="col-sm-3 col-xs-12" id="child_2"></div>
                    <div class="col-sm-3 col-xs-12" id="child_3"></div>
                    @elseif($item == 3)
                    <div class="col-sm-3 col-xs-12" id="child_3"></div>
                    @endif
                    <div class="clearfix"></div>
                </div>
                <div class="from-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">封面图片：</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class="input-group ">
                        	<input type="file" name="thumb" id="thumb" value="" class="form-control" autocomplete="off">
                        </div>
                         <div id="imgbox" class="dustbin">
                            <div style='width:90px; height:60px;float:left;'>
	            	          @if(count($result->attachment)>0)
	            	              <img src='{{$result->attachment->url}}' >
	            	              <input type='hidden' name='thumb' value='{{$result->attachment->id}}'>
	            	          @endif
	            	        </div>
                         </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="description">
                <h4>简介：</h4>
                <div class="form-group">
                    <textarea class="form-control" rows="3" name="description" id="description">{{ $result->description['name'] }}</textarea>
                    <div id="desc_tips"><i class="glyphicon glyphicon-envelope"></i><span class="font-tips">将右侧图库的图片拖入此处</span></div>
                    <div id="desc_img_box" class="dustbin">
                        @if(!empty($result->description['img']))
                        @foreach($result->description['img'] as $desimg)
                        <div style='width:90px; height:60px;float:left;'><img src="{{ $desimg }}"/></div>
                        @endforeach
                        @endif
                    </div>
                </div>
            </div>
            <div class="tools">
                <h4>工具／原料：</h4>
                @foreach($result->tools as $ke=>$tol)
                <div class="form-group" @if($ke==0) id="tools-layout" @endif>
                    <input type="text" class="form-control" name="tools_{{$ke}}" id="tools_{{$ke}}" value="{{ $tol }}" placeholder="工具/原料">
                </div>
                @endforeach
                <div class="form-inline">
                    <div class="form-group">
                        <button type="button" class="btn btn-default btn-block" name="addmoretools" id="addmoretools"><i class="glyphicon glyphicon-plus"></i>添加工具/原料</button>
                    </div>
                </div>
            </div>
            <div class="content-layout">
                <h4>方法／步骤<i class="fa fa-edit fa-fw"></i></h4>
                @foreach($result->content as $key=>$con)
                <div class="form-group" @if($key == 0) id="content-layout" @endif>
                    <textarea class="form-control" rows="4" name="content_{{$key}}" placeholder="在这里输入方法／步骤" id="content_{{$key}}">{{ $con['name'] }}</textarea>
                    <div id="content_tips_{{$key}}"><i class="glyphicon glyphicon-envelope"></i><span class="font-tips">将右侧图库的图片拖入此处</span></div>
                    <div id="content_{{$key}}_img_box" class="dustbin">
                        @if(!empty($con['img']))
                        @foreach($con['img'] as $conimg)
                        <div style='width:90px; height:60px;float:left;'><img src="{{ $conimg }}"/></div>
                        @endforeach
                        @endif
                    </div>
                </div>
                @endforeach
                <div class="form-inline"  id="content-layout">
                    <div class="form-group">
                        <button type="button" class="btn btn-default btn-block" name="addmorecontent" id="addmorecontent"><i class="glyphicon glyphicon-plus"></i>添加方法/步骤</button>
                    </div>
                </div>
                <h4>注意事项</h4>
                @foreach($result->notice as $keyy=>$notice)
                <div class="form-group" @if( $keyy ==0 )id="notice" @endif>
                    <input class="form-control"name="notice_{{$keyy}}" placeholder="注意事项" id="notice_{{$keyy}}" value="{{ $notice }}">
                </div>
                @endforeach
                <div class="form-inline">
                    <div class="form-group">
                        <button type="button" class="btn btn-default btn-block" name="addmorenotice" id="addmorenotice" >
                            <i class="glyphicon glyphicon-plus"></i>
                            添加注意事项
                        </button> 
                    </div>
                </div>
            </div>
            <div class="content-layout end-layout">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">相关标签：</label>
                    <div class="col-sm-9 col-xs-12">
                        <strong id="newstags">
                            @foreach($newstag as $ntag)
                            <a href="">{{ $ntag }}</a>
                            @endforeach
                        </strong>
                        <i class="glyphicon glyphicon-plus" data-toggle="modal" data-target="#myModal"></i>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属学院：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="education" class="form-control" value="{{$result->education}}">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程价格：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="number" name="price" class="form-control" value="{{ count($result->exts)>0 ? $result->exts->price : 0 }}">
                        <div class="help-block" >为0则为免费课程。</div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">作者：</label>
                    <div class="col-sm-3 col-xs-12">
                          <input type="text" class="form-control" name="author" id="author" value="{{$result->author}}">
                    </div>
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">来源：</label>
                    <div class="col-sm-3 col-xs-12">
                          <input type="text" class="form-control" name="from" id="from" value="{{$result->from}}">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">浏览量</label>
                    <div class="col-sm-3 col-xs-12">
                          <input type="number" class="form-control" name="views" id="views" value="{{ count($result->exts)>0 ? $result->exts->views : 0}}">
                    </div>
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">学习人数：</label>
                    <div class="col-sm-3 col-xs-12">
                          <input type="number" class="form-control" name="studys" id="studys" value="{{ count($result->exts)>0 ?$result->exts->studys: 0 }}">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <br/>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否置顶：</label>
                    <div class="col-sm-3 col-xs-12">
                        <label class="radio-inline">
                          <input type="radio" name="top" id="top1" value="1"  @if($result->top == 1) checked @endif> 是
                        </label>
                        <label class="radio-inline">
                          <input type="radio" name="top" id="top2" value="0"  @if($result->top == 0) checked @endif> 否
                        </label>
                     </div>
                     <div class="clearfix"></div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">首页推荐：</label>
                    <div class="col-sm-3 col-xs-12">
                        <label class="radio-inline">
                          <input type="radio" name="is_recommond" value="1"  @if($result->is_recommond == 1) checked @endif> 是
                        </label>
                        <label class="radio-inline">
                          <input type="radio" name="is_recommond"value="0" @if($result->is_recommond == 0) checked @endif> 否
                        </label>
                     </div>
                     <div class="clearfix"></div>
                </div>
                <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
                <input type="hidden" name="teachesType" value="{{$result->teaches_type}}">
                <input type="hidden" name="newsid" value="{{ $result->id }}">  
                {!! csrf_field() !!}
                <div class="form-inline">
                    <div class="form-group">
                      <input type="hidden" name="stauts" value="1">
                      <button type="button" class="btn btn-info" id="publish_save" >
                        <i class="icon-ok bigger-110"></i>
                        Submit
                      </button>
                    </div>
                    <div class="form-group col-xs-offset-1">
                      <button type="reset" class="btn">
                        <i class="icon-undo bigger-110"></i>
                        Reset
                      </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="content-edit-right">
            <div class="upload-img" id="right-upload-img">
                <div class="upload-img-button">
                    <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                </div>
                <div id="imgboxid" class="dragbox">
                </div>
            </div>
        </div>
    </form>
<!-- </div> -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">添加文章标签</h4>
      </div>
      <div class="modal-body">
        <div class="addtags">
          <div class="tags">
            <div class="tags-label fl">已添加：</div>
            <div id="tagsdiv" class="fl"></div>
          </div>
          <form>
              <div class="col-xs-9 fl">
                  <div class="form-group">
                    <input type="text" class="form-control" id="addtags" name="addtags" placeholder="请输入标签（不超过7个字符）">
                  </div>
              </div>
              <div class="col-xs-3 fr">
                  <div class="form-group">
                    <input type="button" class="btn btn-default btn-block" id="savetags" name="savetags" value="添加" >
                  </div>
              </div>
              <div class="clear"></div>
              <div class="col-xs-12" id="errortips"></div>
          </form>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="submittags" data-dismiss="modal">确定</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div> 

<script type="text/javascript">
<!--
$(function(){
	/***图片上传****/
	$("#uploadimg").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        '_token':'{{ csrf_token() }}'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/newsimage',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	            var html="<div class=\"draglist\"  title=\"拖拽我\" draggable=\"true\">"
	            	+"<img src='"+data.url+"' draggable=\"false\" />"
	            	+"</div>"
	            $('#imgboxid').append(html);
	            dragsImages();
// 	            bindImg();
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }
	});
	$("#thumb").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        '_token':'{{ csrf_token() }}',
	        'app':'teaches'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/uploadimg',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	        	var html="<div style='width:90px; height:60px;float:left;'>"
	            	+"<img src='"+data.attach+"' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
	            	+"</div>"
	            $('#imgbox').html(html);
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }

	});
});

// 	$(function(){
// 		$(window).scroll(function() { 
// 			var top = $(window).scrollTop(); 
// 			var leftWidth = $("#content-edit-left").width()+23;
// 			var left= $(window).scrollLeft()+leftWidth; 
// 			 	if(top > 100){
// 	 		    	$("#right-upload-img").css({ left:left + "px", top:"0px" }); 
// 	 			}else{
// 	 				$("#right-upload-img").attr("style","");
// 	 			} 
// 			}); 
// 	});
//-->
</script>
@endsection
